#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->sliderRed->setMinimum(0);
    ui->sliderRed->setMaximum(255);
    ui->sliderRed->setSingleStep(5);
    ui->sliderRed->setPageStep(20);
    ui->sliderRed->setOrientation(Qt::Horizontal);

    ui->sliderGreen->setMinimum(0);
    ui->sliderGreen->setMaximum(255);
    ui->sliderGreen->setSingleStep(5);
    ui->sliderGreen->setPageStep(20);
    ui->sliderGreen->setOrientation(Qt::Horizontal);

    ui->sliderBlue->setMinimum(0);
    ui->sliderBlue->setMaximum(255);
    ui->sliderBlue->setSingleStep(5);
    ui->sliderBlue->setPageStep(20);
    ui->sliderBlue->setOrientation(Qt::Horizontal);
}

Widget::~Widget()
{
    delete ui;
}

/** 红色值的QSlider值变化
 * @brief Widget::on_sliderRed_valueChanged
 * @param value
 */
void Widget::on_sliderRed_valueChanged(int value)
{
    QString red = QString::number(value);
    QString green = QString::number(ui->sliderGreen->value());
    QString blue = QString::number(ui->sliderRed->value());

    ui->leRed->setText(red);

    // background-color: rgb(255, 85, 255);
    QString style = "background-color: rgb(" + red + ", " + green + ", " + blue + ");";
    ui->lineEdit->setStyleSheet(style);
}

/** 绿色值的QSlider值变化
 * @brief Widget::on_sliderGreen_valueChanged
 * @param value
 */
void Widget::on_sliderGreen_valueChanged(int value)
{
    QString red = QString::number(ui->sliderRed->value());
    QString green = QString::number(value);
    QString blue = QString::number(ui->sliderRed->value());


    ui->leGreen->setText(green);

    QString style = "background-color: rgb(" + red + ", " + green + ", " + blue + ");";
    ui->lineEdit->setStyleSheet(style);
}

/** 蓝色值的QSlider值变化
 * @brief Widget::on_sliderBlue_valueChanged
 * @param value
 */
void Widget::on_sliderBlue_valueChanged(int value)
{
    QString red = QString::number(ui->sliderRed->value());
    QString green = QString::number(ui->sliderGreen->value());
    QString blue = QString::number(value);

    ui->leBlue->setText(blue);

    QString style = "background-color: rgb(" + red + ", " + green + ", " + blue + ");";
    ui->lineEdit->setStyleSheet(style);
}

